//
//  UIView+KKAdditions.h
//  KKonry
//
//  Created by Jonas Budelmann on 20/07/13.
//  Copyright (c) 2013 cloudling. All rights reserved.
//

#import "KKUtilities.h"
#import "KKConstraintMaker.h"
#import "KKViewAttribute.h"

/**
 *	Provides constraint maker block
 *  and convience methods for creating KKViewAttribute which are view + NSLayoutAttribute pairs
 */
@interface KK_VIEW (KKAdditions)

/**
 *	following properties return a new KKViewAttribute with current view and appropriate NSLayoutAttribute
 */
@property (nonatomic, strong, readonly) KKViewAttribute *KK_left;
@property (nonatomic, strong, readonly) KKViewAttribute *KK_top;
@property (nonatomic, strong, readonly) KKViewAttribute *KK_right;
@property (nonatomic, strong, readonly) KKViewAttribute *KK_bottom;
@property (nonatomic, strong, readonly) KKViewAttribute *KK_leading;
@property (nonatomic, strong, readonly) KKViewAttribute *KK_trailing;
@property (nonatomic, strong, readonly) KKViewAttribute *KK_width;
@property (nonatomic, strong, readonly) KKViewAttribute *KK_height;
@property (nonatomic, strong, readonly) KKViewAttribute *KK_centerX;
@property (nonatomic, strong, readonly) KKViewAttribute *KK_centerY;
@property (nonatomic, strong, readonly) KKViewAttribute *KK_baseline;
@property (nonatomic, strong, readonly) KKViewAttribute *(^KK_attribute)(NSLayoutAttribute attr);

@property (nonatomic, strong, readonly) KKViewAttribute *KK_firstBaseline;
@property (nonatomic, strong, readonly) KKViewAttribute *KK_lastBaseline;

#if TARGET_OS_IPHONE || TARGET_OS_TV

@property (nonatomic, strong, readonly) KKViewAttribute *KK_leftMargin;
@property (nonatomic, strong, readonly) KKViewAttribute *KK_rightMargin;
@property (nonatomic, strong, readonly) KKViewAttribute *KK_topMargin;
@property (nonatomic, strong, readonly) KKViewAttribute *KK_bottomMargin;
@property (nonatomic, strong, readonly) KKViewAttribute *KK_leadingMargin;
@property (nonatomic, strong, readonly) KKViewAttribute *KK_trailingMargin;
@property (nonatomic, strong, readonly) KKViewAttribute *KK_centerXWithinMargins;
@property (nonatomic, strong, readonly) KKViewAttribute *KK_centerYWithinMargins;

@property (nonatomic, strong, readonly) KKViewAttribute *KK_safeAreaLayoutGuide NS_AVAILABLE_IOS(11.0);
@property (nonatomic, strong, readonly) KKViewAttribute *KK_safeAreaLayoutGuideLeading NS_AVAILABLE_IOS(11.0);
@property (nonatomic, strong, readonly) KKViewAttribute *KK_safeAreaLayoutGuideTrailing NS_AVAILABLE_IOS(11.0);
@property (nonatomic, strong, readonly) KKViewAttribute *KK_safeAreaLayoutGuideLeft NS_AVAILABLE_IOS(11.0);
@property (nonatomic, strong, readonly) KKViewAttribute *KK_safeAreaLayoutGuideRight NS_AVAILABLE_IOS(11.0);
@property (nonatomic, strong, readonly) KKViewAttribute *KK_safeAreaLayoutGuideTop NS_AVAILABLE_IOS(11.0);
@property (nonatomic, strong, readonly) KKViewAttribute *KK_safeAreaLayoutGuideBottom NS_AVAILABLE_IOS(11.0);
@property (nonatomic, strong, readonly) KKViewAttribute *KK_safeAreaLayoutGuideWidth NS_AVAILABLE_IOS(11.0);
@property (nonatomic, strong, readonly) KKViewAttribute *KK_safeAreaLayoutGuideHeight NS_AVAILABLE_IOS(11.0);
@property (nonatomic, strong, readonly) KKViewAttribute *KK_safeAreaLayoutGuideCenterX NS_AVAILABLE_IOS(11.0);
@property (nonatomic, strong, readonly) KKViewAttribute *KK_safeAreaLayoutGuideCenterY NS_AVAILABLE_IOS(11.0);

#endif

/**
 *	a key to associate with this view
 */
@property (nonatomic, strong) id KK_key;

/**
 *	Finds the closest common superview between this view and another view
 *
 *	@param	view	other view
 *
 *	@return	returns nil if common superview could not be found
 */
- (instancetype)KK_closestCommonSuperview:(KK_VIEW *)view;

/**
 *  Creates a KKConstraintMaker with the callee view.
 *  Any constraints defined are added to the view or the appropriate superview once the block has finished executing
 *
 *  @param block scope within which you can build up the constraints which you wish to apply to the view.
 *
 *  @return Array of created KKConstraints
 */
- (NSArray *)KK_makeConstraints:(void(NS_NOESCAPE ^)(KKConstraintMaker *make))block;

/**
 *  Creates a KKConstraintMaker with the callee view.
 *  Any constraints defined are added to the view or the appropriate superview once the block has finished executing.
 *  If an existing constraint exists then it will be updated instead.
 *
 *  @param block scope within which you can build up the constraints which you wish to apply to the view.
 *
 *  @return Array of created/updated KKConstraints
 */
- (NSArray *)KK_updateConstraints:(void(NS_NOESCAPE ^)(KKConstraintMaker *make))block;

/**
 *  Creates a KKConstraintMaker with the callee view.
 *  Any constraints defined are added to the view or the appropriate superview once the block has finished executing.
 *  All constraints previously installed for the view will be removed.
 *
 *  @param block scope within which you can build up the constraints which you wish to apply to the view.
 *
 *  @return Array of created/updated KKConstraints
 */
- (NSArray *)KK_remakeConstraints:(void(NS_NOESCAPE ^)(KKConstraintMaker *make))block;

@end
